/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.performer_main;

/**
 *
 * @author Dragan
 */

import javax.swing.*;
import java.awt.*;
import java.util.Vector;

public class ProjectPanel extends javax.swing.JPanel  {
    
    /**
     * Creates new form ProjectPanel
     */
    
    //Thread treeThread;
    CheckNodeTreePanel treePanel;
    
    //public ProjectPanel(String treePath) {
    public ProjectPanel() {
        initComponents();
        
       

        //jPanel1 = new FileTreePanel(MainWindow.runningProject.getLocation());
        jPanel1.setLayout(new GridLayout(1,0));
        treePanel = new CheckNodeTreePanel();
        //jPanel1 = new CheckNodeTreePanel();
        //treeThread = new Thread(treePanel);
        jPanel1.add(treePanel);
        
        //treeThread.start();
        
        //jPanel1.add(new FileTreePanel(MainWindow.runningProject.getStudentsRootFolder(),
        //                              MainWindow.runningProject.getTestsRootFolder()));
        //jPanel1.setVisible(true);
        
        jPanel4.setLayout(new GridLayout(1,1));

        

        
        jPanel3.setLayout(new GridLayout(0,1));
        jPanel3.add(new javax.swing.JScrollPane());
        
        
        
        //listModel.clear();
    }
  /*  
    public ProjectPanel(javax.swing.JFrame parent) {
        this();
        this.parent = parent;
    }

    public javax.swing.JFrame getParent()
    {
        return parent;
    }
 */   
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();

        jButton2.setText("Properties");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Add Test");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Test Selected");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Test All");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("Update");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jPanel4.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                jPanel4ComponentResized(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 402, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 142, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 247, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 305, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jButton2)
                        .addGap(18, 18, 18)
                        .addComponent(jButton3)
                        .addGap(18, 18, 18)
                        .addComponent(jButton6)
                        .addGap(13, 13, 13))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(47, 47, 47)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addComponent(jButton4)
                        .addGap(18, 18, 18)
                        .addComponent(jButton5)
                        .addContainerGap(202, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3)
                    .addComponent(jButton4)
                    .addComponent(jButton5)
                    .addComponent(jButton6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(166, 166, 166))
        );
    }// </editor-fold>//GEN-END:initComponents
          
    
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        //fileChooser2.showDialog(this);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        //(new ProjectSettingsDialog((javax.swing.JFrame)this.getParent(),true)).setVisible(true);
        MainWindow.appMainWindow.projectSettings();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        for (Student s : MainWindow.runningProject.getStudents())
        {
            s.getStudentEvent().addEventListener(StudentRepresentationModel.findNodeByStudent(s));
        }        
        CheckNodeTreePanel.refreshPanel(jPanel1);
        validate();     
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        //if (MainWindow.runningProject.tests.isEmpty())
        //{
        //    JOptionPane.showMessageDialog(MainWindow.runningProject.getProjectPanel(), "There's no test!");
        //    return;
        //}
        
        for (StudentRepresentationModel s : Project.studentsNodes) s.getCheckNode().isSelected = true;
        
           // MainWindow.runningProject.tests.elementAt(0).executeAndCollectResults(MainWindow.runningProject.getStudents());//,jPanel3);
        //MainWindow.runningProject.tests.elementAt(0).executeAndCollectResults();
        
        //MainWindow.runningProject.tests.elementAt(0).setStudentsAndPanel(MainWindow.runningProject.getStudents(),jPanel3);
        //MainWindow.runningProject.tests.elementAt(0).run();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jPanel4ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jPanel4ComponentResized
       //jPanel4.getComponent(0).setSize(jPanel4.getHeight(), jPanel4.getWidth());
    }//GEN-LAST:event_jPanel4ComponentResized

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        //if (MainWindow.runningProject.tests.isEmpty())
        //{
        //   JOptionPane.showMessageDialog(MainWindow.runningProject.getProjectPanel(), "There's no test!");
        //    return;
       // }
        //MainWindow.runningProject.tests.elementAt(0).executeAndCollectResults();

        /*
        Vector<Student> studentsForTesting = new Vector<Student>();
        for (StudentRepresentationModel srm : Project.studentsNodes)
        {
            CheckNode n = srm.getCheckNode();
            if (n.isSelected) studentsForTesting.add(srm.getStudent());
        }
        for (Student s: studentsForTesting) System.out.println(s);
        MainWindow.runningProject.tests.elementAt(0).executeAndCollectResults(studentsForTesting);
        */
        /*
        Vector<Student> st = MainWindow.runningProject.getStudents();
        Student s = st.elementAt(3);
        System.out.print(s + " change result");
        s.setTestResult("PASS");
        * 
        */
        /*
        File dir = new File("D:\\Performer\\NewProject\\Assignments");
        File[] list = dir.listFiles();
        for (File f : list)
            System.out.println(Project.studentCache.get(f));
        
        */
    }//GEN-LAST:event_jButton4ActionPerformed

    private void checkForTriggerEvent(java.awt.event.MouseEvent e )  
    {  
        if ( e.isPopupTrigger() ) popupMenu.show( e.getComponent(), e.getX(), e.getY() );  
    }  
    
    private MyFileChooser fileChooser1 = new MyFileChooser("Save");
    private MyFileChooser fileChooser2 = new MyFileChooser("Add");
    private DefaultListModel listModel = new DefaultListModel();
    private JPopupMenu popupMenu = new JPopupMenu();
    private JMenuItem moreInfo = new JMenuItem("Vise informacija");
   // private DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode();
    
    private Point popupMenuPoint;
     


 
  //  private javax.swing.JFrame parent;
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    // End of variables declaration//GEN-END:variables

   
    /*
    private void makeIconButton (String iconPath, javax.swing.JButton button)
    {
       button.setIcon(new ImageIcon(iconPath));
        button.setBorderPainted(false);   
        button.setFocusPainted(false);   
        button.setContentAreaFilled(false);
    }
    
    private void setAppropriateIcons ()
    {
        makeIconButton("D:/saveButton", jButton1);
    }
    */
    
   


	

	
}
    

